<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionController::Head</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionController::Head 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/actionpack/lib/action_controller/metal/head_rb.html">actionpack/lib/action_controller/metal/head.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>H</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Head.html#method-i-head">head</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-head">
            
              <b>head</b>(status, options = {})
            
            <a href="Head.html#method-i-head" name="method-i-head" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Return a response that has no content (merely headers). The options
argument is interpreted to be a hash of header names and values. This
allows you to easily return a response that consists only of significant
headers:</p>

<pre>head :created, location: person_path(@person)

head :created, location: @person</pre>

<p>It can also be used to return exceptional conditions:</p>

<pre>return head(:method_not_allowed) unless request.post?
return head(:bad_request) unless valid_request?
render</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-head_source')" id="l_method-i-head_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b8c2f3c7692867dfd444d60efb18570ad0fba236/actionpack/lib/action_controller/metal/head.rb#L19" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-head_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/head.rb, line 19</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">head</span>(<span class="ruby-identifier">status</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">options</span>, <span class="ruby-identifier">status</span> = <span class="ruby-identifier">status</span>, <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
  <span class="ruby-identifier">status</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:status</span>) <span class="ruby-operator">||</span> <span class="ruby-value">:ok</span>
  <span class="ruby-identifier">location</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:location</span>)
  <span class="ruby-identifier">content_type</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:content_type</span>)

  <span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">headers</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">dasherize</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'-'</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>[<span class="ruby-number">0</span>] = <span class="ruby-identifier">v</span>[<span class="ruby-number">0</span>].<span class="ruby-identifier">chr</span>.<span class="ruby-identifier">upcase</span> }.<span class="ruby-identifier">join</span>(<span class="ruby-string">'-'</span>)] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">status</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">location</span> = <span class="ruby-identifier">url_for</span>(<span class="ruby-identifier">location</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">location</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">include_content?</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">status</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">content_type</span> = <span class="ruby-identifier">content_type</span> <span class="ruby-operator">||</span> (<span class="ruby-constant">Mime</span>[<span class="ruby-identifier">formats</span>.<span class="ruby-identifier">first</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">formats</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">response</span>.<span class="ruby-identifier">charset</span> = <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">response</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">response_body</span> = <span class="ruby-string">&quot; &quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-string">'Content-Type'</span>)
    <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-string">'Content-Length'</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">response_body</span> = <span class="ruby-string">&quot;&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    